package com.zjf.bbs.service.impl.medal;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zjf.bbs.dao.MedalDao;
import com.zjf.bbs.dao.UserDao;
import com.zjf.bbs.entity.Medal;
import com.zjf.bbs.entity.User;
import com.zjf.bbs.service.medal.MedalIssueService;
@Service(value="medalIssueService")
public class MedalIssueServiceImpl implements MedalIssueService {
	@Resource(name="userDao")
	private UserDao userDao;
	@Resource(name="medalDao")
	private MedalDao medalDao;
	public void issue(User user, Set<Medal> medals) {
		Set<Medal> userMedals=new LinkedHashSet<Medal>();
		for(Medal m:medals){
			m = medalDao.load(Medal.class, m.getId());
			userMedals.add(m);
		}
		user.setMedals(userMedals);
		userDao.update(user);
	}
	public void issue(User user, Medal medal) {
		Set<Medal> medals = new LinkedHashSet<Medal>();
		medals.add(medal);
		issue(user, medals);
		
	}
	

}
